package com.fram.controller.admin;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fram.bean.admin.projectplanttechnology.request.ProjectPlantTechnologyAdminSearchRequest;
import com.fram.bean.sys.PageBean;
import com.fram.bean.sys.ResponseMsg;
import com.fram.common.canstant.ErrCode;
import com.fram.common.exception.ProAffairException;
import com.fram.common.util.PublicMethod;
import com.fram.common.util.apiversion.ApiVersion;
import com.fram.common.util.base.BaseAdminController;
import com.fram.entity.ProjectPlantTechnology;
import com.fram.service.admin.ProjectPlantTechnologyAdminService;

/**
 * @作者： 陳曉鬆 @时间： 2020年10月12日 - 上午10:41:22 @description：->
 */
@RestController
@RequestMapping("/admin/{version}/auth/project/planttechnology")
public class ProjectPlantTechnologyAdminController extends BaseAdminController {

	private static Logger LOG = LoggerFactory.getLogger(ProjectPlantTechnologyAdminController.class);

	@Resource(name = "projectPlantTechnologyAdminService")
	private ProjectPlantTechnologyAdminService projectPlantTechnologyAdminService;

	@ApiVersion(1.0)
	@RequestMapping("list")
	private ResponseMsg list(@RequestBody PageBean<ProjectPlantTechnologyAdminSearchRequest> request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			msg.setData(projectPlantTechnologyAdminService.search(request));
		} catch (ProAffairException e) {
			LOG.error("-技术-查询列表出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-技术-查询列表异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("add")
	private ResponseMsg add(@RequestBody ProjectPlantTechnology request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			projectPlantTechnologyAdminService.add(request);
		} catch (ProAffairException e) {
			LOG.error("-技术-添加出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-技术-添加异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}

	@ApiVersion(1.0)
	@RequestMapping("update")
	private ResponseMsg update(@RequestBody ProjectPlantTechnology request) {
		ResponseMsg msg = ResponseMsg.returnBeanBuild();
		try {
			projectPlantTechnologyAdminService.update(request);
		} catch (ProAffairException e) {
			LOG.error("-技术-修改出错->{},{},{}", msg.getSessionId(), e.getErrorCode(), e.getErrorMsg());
			msg.setReturnCode(e.getErrorCode()).setReturnMsg(e.getErrorMsg());
		} catch (Exception e) {
			LOG.error("-技术-修改异常->{},{}", msg.getSessionId(), PublicMethod.printErrorTrace(e));
			msg.setReturnCode(ErrCode.ERR.getReturnCode()).setReturnMsg(ErrCode.ERR.getReturnMsg());
		}
		return msg;
	}
}
